package org.flower.web.servlet;

import org.flower.dao.AdminUserDao;
import org.flower.dao.impl.AdminUserDaoImpl;
import org.flower.entity.AdminUser;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/**
 * @author Aizen
 */
@WebServlet("/manager/adminLoginServlet")
public class AdminLoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        AdminUserDao adminUserDao = new AdminUserDaoImpl();
        AdminUser adminUser = adminUserDao.getAdminUser(username,password);
        if(adminUser!=null){
            request.getSession().setAttribute("adminUser",adminUser);
            response.sendRedirect("manageServlet");
        }else{
            response.sendRedirect("adminLogin.jsp");
        }
    }
}
